# Maintainer: Andrei Zavada <andrei.zavada@tiot.jp>
pkgname=stanchion
pkgver=3.0.0
_pkgtag=3.0.0
pkgrel=0
pkgdesc="Request serialization for Riak CS"
url="https://github.com/TI-Tokyo/stanchion"
arch="all !riscv64" # erlang22
license="Apache-2.0"
depends="bash"
makedepends="erlang22 erlang22-dev erlang22-dialyzer"
subpackages="$pkgname-openrc"
source="
	stanchion-$_pkgtag.tar.gz::https://github.com/TI-Tokyo/stanchion/archive/refs/tags/$_pkgtag.tar.gz
	stanchion.initd
	"
builddir="$srcdir/stanchion-$_pkgtag"

build() {
	git config --global url."https://".insteadOf git://
	make rel-alpine
}

check() {
	make test
}

package() {
	reldir="$PWD/rel/stanchion"
	mkdir -p "$pkgdir/usr/bin"
	mkdir -p "$pkgdir/usr/sbin"
	mkdir -p "$pkgdir/usr/lib/stanchion"
	mkdir -p "$pkgdir/var/lib/stanchion"
	mkdir -p "$pkgdir/var/log/stanchion"
	mkdir -p "$pkgdir/etc/stanchion"
	mkdir -p "$pkgdir/run/stanchion"
	for f in stanchion-admin stanchion-debug; do
	    cp "$reldir/bin/$f" "$pkgdir/usr/bin"
	done
	cp "$reldir/usr/bin/stanchion" "$pkgdir/usr/sbin"
	install "$reldir/etc/stanchion.conf" "$pkgdir/etc/stanchion/stanchion.conf"
	cp -R "$reldir"/bin        "$pkgdir/usr/lib/stanchion"
	cp -R "$reldir"/etc/*      "$pkgdir/etc/stanchion"
	cp -R "$reldir"/erts-*     "$pkgdir/usr/lib/stanchion"
	cp -R "$reldir"/share      "$pkgdir/usr/lib/stanchion"
	cp -R "$reldir"/releases   "$pkgdir/usr/lib/stanchion"
	cp -R "$reldir"/lib        "$pkgdir/usr/lib/stanchion"

	install -m755 -D "$srcdir"/stanchion.initd \
		"$pkgdir"/etc/init.d/stanchion
}

sha512sums="
a83e0758bf1352ef5c65b23825ff8c02be987c1e34565064b178dfcebf329b7475ef9f1c4a90b82da28ee4a00f4dac90514571e4e5b740301dddc252b0c8ec3b  stanchion-3.0.0.tar.gz
33d53436b9b64debc3234590a1e10a03091e16f9c99742d22c4063016d83e47033a85d9d907569060ded9881f1ccb98f65403c872123c7242a8ff64cbe27abc2  stanchion.initd
"
